using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Collections;

using Domain;

using Server;
using Server.Manager;

namespace Server.View
{
    public partial class ServerForm : Form
    {
        // Constructor
        public ServerForm()
        {
            InitializeComponent();
        }

        // Event functions
        private void btnStart_Click(object sender, EventArgs e)
        {
            // Start
            Server.Instance.Listen(Int32.Parse(txfPort.Text));
        }

        private void btnRestart_Click(object sender, EventArgs e)
        {
            // Close
            Server.Instance.Close();

            // Start
            Server.Instance.Listen(Int32.Parse(txfPort.Text));
        }

        private void btnStop_Click(object sender, EventArgs e)
        {
            // Close
            Server.Instance.Close();
        }

        private void btnTest_Click(object sender, EventArgs e)
        {
            ArrayList collection = PlayerManager.getPlayers();

            txfDebug.Text += "Testing Database...\r\n";

            foreach (Player obj in collection)
            {
                txfDebug.Text += "Player '" + obj.Name + "' found!\r\n";
            }

            txfDebug.Text += collection.Count + " players retrieved.\r\n";
        }

        private void btnRefresh_Click(object sender, EventArgs e)
        {
            // Check count
            txfCount.Text = Server.Instance.Clients.Count + "";
        }
    }
}